#include "ErlangRandom.h"
#include "ExponentialRandom.h"

ErlangRandom::ErlangRandom(double lambda, int k)
{
    this->lambda = lambda;
    this->k = k;
    for(int i = 0; i < k; i++)
        this->exponentialRandoms.append(new ExponentialRandom(k * lambda));
}

double ErlangRandom::Next()
{
    double result = 0;
    QLinkedListIterator<ExponentialRandom*> i(this->exponentialRandoms);
    while(i.hasNext())
    {
        result += i.next()->Next();
    }

    return result;
}
